# encoding: utf-8

import logging
import subprocess
import ctypes
import sys
from Login import *

##############
#author:张子路#
##############

class RightsGet():

    def __init__(self):
        pass

    def is_admin(self):
        try:
            return ctypes.windll.shell32.IsUserAnAdmin()
        except:
            return False

    def AdminCmdRun(self,cmd):
        try:
            res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            for line in res.communicate():
                return(line.decode("GBK"))
        except Exception as e:
            logging.error("执行命令失败 {0}".format(e), exc_info=True)

    def RegistryRightsGet(self,Path,User):
        try:
            CmdStr='SetACL.exe -on "{0}" -ot reg -actn ace -ace "n:{1};p:full"'.format(Path,User)        #获取注册表读取权限
            self.AdminCmdRun(CmdStr)
        except Exception as e:
            logging.error("获取权限失败 {0}".format(e), exc_info=True)

if __name__ == "__main__":
    login=LoginStart()
    login.start()